package DataStructure.graph;

import DataStructure.linear.Queue;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class DijkstraSPTest {
    public static void main(String[] args) throws Exception{
        //创建一副加权有向图
        BufferedReader br = new BufferedReader(new InputStreamReader(DijkstraSPTest.class.getClassLoader().getResourceAsStream("min_route_test.txt")));
        int total = Integer.parseInt(br.readLine());
        EdgeWeightedDigraph G = new EdgeWeightedDigraph(total);
        int edgeNumber = Integer.parseInt(br.readLine());
        for (int i = 1; i <= edgeNumber; i++) {
            String line = br.readLine();
            String[] str = line.split(" ");
            int v = Integer.parseInt(str[0]);
            int w = Integer.parseInt(str[1]);
            double weight = Double.parseDouble(str[2]);
            DirectedEdge e = new DirectedEdge(v,w,weight);
            G.addEdge(e);
        }
        //创建sp对象，
        DijkstraSP sp = new DijkstraSP(G, 0);
        //查找最短路径
        Queue<DirectedEdge> edges = sp.pathTo(6);
        //遍历打印
        for (DirectedEdge e : edges) {
            System.out.println(e.from()+"->"+e.to()+"::"+e.weight());
        }
    }
}
